/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022.
 * Description:  rtos_network_down.c
 * Author: songzhezhe <songzhezhe@huawei.com>
 * Create: 2022-03-05
 */

#include <linux/types.h>
#include <linux/libfdt.h>
#include <mach/be8_compatible.h>
#include <asm/io.h>
#include "rtos_parse_cmdline.h"

static void do_newtwork_shutdown(unsigned long addr)
{
	/*
	 * the way to shutdown network is provieded by marp
	 * and has been verifyed on V3_FDD
	 */
	io_write(addr, 0xF);
}

void v3fdd_network_down(void *dtb)
{
	int node;
	char *bootargs = NULL;
	char *p = NULL;
	int size;
	unsigned long addr = 0;

	node = fdt_subnode_offset(dtb, 0, "chosen");
	if (node < 0)
		return;

	bootargs = (char *)fdt_getprop(dtb, node, "bootargs", &size);
	if (bootargs == NULL)
		return;

	p = find_str_in_bootargs(bootargs, "network_down");
	if (p) {
		p += strlen("network_down");
		while (*p == ' ' || *p == '=')
			p++;
		addr = parse_mem(p, &size);
		if (addr)
			do_newtwork_shutdown(addr);
	}
}
